﻿using System;
using MockDataAccess;
using MockDataTransferObject;
using System.Data;
using System.Collections.ObjectModel;

namespace MockBusiness
{
    public class RoleBusiness
    {
        #region Initialize
        private static RoleBusiness _instance;
        private readonly RoleDataAccess _roleDataAccess;

        /// <summary>
        /// Gets the role data test.
        /// </summary>
        public Collection<Role> RoleDataTest
        {
            get
            {
                return _roleDataAccess.AffectedRows;
            }
        }

        /// <summary>
        /// Prevents a default instance of the <see cref="RoleBusiness"/> class from being created.
        /// </summary>
		private RoleBusiness()
        {
            _roleDataAccess = new RoleDataAccess();
        }

        /// <summary>
        /// Prevents a default instance of the <see cref="RoleBusiness"/> class from being created.
        /// </summary>
        /// <param name="isFake">if set to <c>true</c> [is fake].</param>
        private RoleBusiness(bool isFake)
        {
            _roleDataAccess = new RoleDataAccess(isFake);
        }

        /// <summary>
        /// Retrieves the instance.
        /// </summary>
        /// <returns></returns>
        public static RoleBusiness RetrieveInstance()
        {
            if (_instance == null)
                _instance = new RoleBusiness();
            return _instance;
        }

        /// <summary>
        /// Retrieves the instance.
        /// </summary>
        /// <param name="isFake">if set to <c>true</c> [is fake].</param>
        /// <returns></returns>
        public static RoleBusiness RetrieveInstance(bool isFake)
        {
            if (_instance == null)
                _instance = new RoleBusiness(isFake);
            return _instance;
        }
        #endregion

        #region CUD
        #endregion

        #region R
        /// <summary>
        /// Retrieves all roles.
        /// </summary>
        /// <returns></returns>
        public DataTable RetrieveAllRoles()
        {
            return _roleDataAccess.RetrieveAllRoles();
        }

        /// <summary>
        /// Gets the by id.
        /// </summary>
        /// <param name="roleId">The role id.</param>
        /// <returns></returns>
        public Role GetById(object roleId)
        {
            return _roleDataAccess.GetById(roleId);
        }

        /// <summary>
        /// Gets the name of the role id by role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        /// <returns></returns>
        public object GetRoleIdByRoleName(string roleName)
        {
            if (roleName == null)
                return null;
            return _roleDataAccess.GetRoleIdByRoleName(roleName);
        }
        #endregion
    }
}
